package org.bigmarketapi.projectreview.CompletableFuture;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.*;

import static java.util.concurrent.Executors.newFixedThreadPool;

/**
 * @BelongsProject: ProjectReview
 * @BelongsPackage: org.bigmarketapi.projectreview.CompletableFuture
 * @Author: dujiaqi
 * @CreateTime: 2024-08-13  14:03
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class completableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ICompletableService service = new ICompletableService();
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(dateFormat.format(new Date()));
        ExecutorService executorService = newFixedThreadPool(10);
        for (int i = 0; i < 10000; i++) {
            final CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> service.getValue("hello"), executorService);
            future.get();
        }
        System.out.println(dateFormat.format(new Date()));
    }
}
